package com.gaoboy.springbootgoods.service.impl;

import com.gaoboy.springbootgoods.entity.Goods;
import com.gaoboy.springbootgoods.mapper.GoodsMapper;
import com.gaoboy.springbootgoods.service.GoodsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;


    @Override
    public PageInfo<Goods> queryBynamicFields(Integer pageNum, String name, Date startdate, Date enddate) {

        Date sDate = startdate;
        Date eDate = enddate;

        if(sDate == null){
            sDate = new Date(0,1,1);
        }
        if (eDate==null){
            eDate=new Date(130,1,1);
        }
        PageHelper.startPage(pageNum,2);
        List<Goods>goods = goodsMapper.queryByDynamicFields(name,sDate,enddate);
        PageInfo<Goods>pageInfo = new PageInfo<>(goods);

        return pageInfo;
    }
}
